Skip to content

Comments

Convert LazyFile/LazyBlob to standalone classes#10913

Merged
markdalgleish merged 4 commits intomainfrom
markdalgleish/remove-file-blob-subclassing
Jan 6, 2026
Merged

Convert LazyFile/LazyBlob to standalone classes#10913
markdalgleish merged 4 commits intomainfrom
markdalgleish/remove-file-blob-subclassing

Conversation

@markdalgleish
Copy link
Member

This PR removes subclassing from LazyFile/LazyBlob to fix compatibility issues with Bun's native optimizations and updates all consumers to use the new APIs.

  • @remix-run/lazy-file no longer extends native File/Blob. Instead, LazyFile and LazyBlob implement the same interface as standalone classes. Users must now call .stream() for Response bodies or .toFile()/.toBlob() for APIs requiring native types (e.g. FormData).
  • @remix-run/fs has renamed openFile() to openLazyFile() and removed the getFile() alias to explicitly reflect that it returns a LazyFile, not a native File.
  • @remix-run/response now accepts any file-like object via a generic FileLike interface, supporting both native File and LazyFile.
  • @remix-run/file-storage and @remix-run/static-middleware have been updated to use the new openLazyFile() API.

@markdalgleish markdalgleish changed the title Convert LazyFile/LazyBlob to standalone classes Convert LazyFile/LazyBlob to standalone classes Dec 19, 2025
@MichaelDeBoey
Copy link
Member

@markdalgleish If this PR is created to fix what @kentcdodds mentioned in #10872 (comment), an alternative could be to go with something like @alexandredev3's solution from #10889

@markdalgleish
Copy link
Member Author

@MichaelDeBoey Thanks for the heads up. We were aware of this and explored what a complete solution would look like here: #10904. We've opted instead to simplify the model and avoid this category of issue entirely.

Copy link
Member

@mjackson mjackson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small changes, but overall this is an excellent PR. Thanks, @markdalgleish!


// Type assertions: ensure LazyBlob and LazyFile implement all native Blob/File APIs.
null as unknown as LazyBlob satisfies Record<keyof Blob, unknown>
null as unknown as LazyFile satisfies Record<keyof File, unknown>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍

@markdalgleish markdalgleish merged commit 97237e3 into main Jan 6, 2026
5 checks passed
@markdalgleish markdalgleish deleted the markdalgleish/remove-file-blob-subclassing branch January 6, 2026 05:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants